Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX OIDC token selection for sourcing "member_of" or "roles" claim #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aherkstroeter-ms
Copy link

Problem: "member_of" and "roles" claims in id_token ignored

Since there should also be an access_token, when something other than keycloak is being used, this function results in the id_token being ignored, regardless of whether or not the access_token contains the needed claims or not.

  def user
    if access_token? # keycloak way...
      @user = JSON::parse(Base64::decode64(access_token.split('.')[1]))
    else
      @user = JSON::parse(Base64::decode64(id_token.split('.')[1]))
    end
    return @user
  end

Fix: Checking the content of the access_token

checking the content of the access_token like this resolves the problem

    if access_token?
      token = JSON::parse(Base64::decode64(access_token.split('.')[1]))
      if token["member_of"].present? || token["roles"].present?
        @user = token
      end
    end

if it does not contain the claims, we default to the id_token

    # user info from id_token, the regular way...
    @user = JSON.parse(Base64.decode64(id_token.split('.')[1]))
    return @user
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant